Test::MockDBI v0.50 is wending its way through CPAN, even as I write this. Test::MockDBI uses Test::MockObject::Extends to mock up the whole DBI interface for testing. Rules for DBI behavior are set up, then the standard output of the containing program can be examined for matching patterns.
Mocking up the whole DBI interface is useful for us consultants, as the Test::MockDBI code can be added to an existing program without that program's knowledge, allowing you to test the program's use of DBI without modifying the base code of the program -- or for that matter, hitting an actual database at all (unless you want to).
The rules can be sensitive to what SQL is currently being processed, as well as depending on a numeric DBI testing type. Wildcarding is allowed, so if you have some DBI processing that is done by all programs, you can set up that processing without it interfering with testing your specific program's DBI usage.
Test::MockDBI is an improvement over DBD::Mock or DBI::trace(), as you can modify the mocked-up DBI's behavior to force conditions to occur that might be difficult or impossible to otherwise force to occur.
Test::MockDBI v0.50 is marked as alpha code, because although what I have written and tested is beta or production-quality code, not all of the DBI is mocked-up yet. If anyone has a good idea on how DBI::quote() should work in Test::MockDBI, I would love to hear from you.
What exactly would you like to see DBD::Mock do that it doesn't? I am happy to take suggestions and/or patches.
- stvnFirst off, I view DBD::Mock, Test::MockDBI, and DBI::trace() as complementary, as they each take a somewhat different tack to the same problem.
Although I finally realize that you can use DBD::Mock for similar purposes as Test::MockDBI, the current documentation (at least) is geared more towards using DBD::Mock as a tracing tool. My docs for Test::MockDBI explicitly stress changing the DBI behavior.
Plus, DBD::Mock is good for situations where you use configurable data sources, while Test::MockDBI is good when you need to insert DBI debugging code without changing the base code of a program (something I've had to do a lot lately as a consultant).
My suggestion for DBD::Mock is to stress changing the DBI behavior in the documentation, so as to tease out those edge cases and difficult/impossible to otherwise generate failures. Meanwhile, I will look again at DBD::Mock for what I can learn from it.
Thanks for your comments!
Re:DBD::Mock and Test::MockDBI
stvn on 2005-01-19T19:38:40
I too see them as complementary (at least as much as I can glean of what Test::MockDBI does). I would actually be very interested in seeing more information on Test::MockDBI if you care to provide it
:) I am actually planning a re-write parts of the DBD::Mock docs when I have some time to better show some of it's newer features. I will take your suggestions, and also try to stress it's role in testing more as well.
You are correct that DBD::Mock cannot really insert debugging code, and it only allows some changes in the DBI behavior (it can support more, I just haven't found a need yet). In the end, DBD::Mock will always be limited in what it can do because it is a DBD. Whereas Test::MockDBI will not have such limits.
-stvn